//
//  UITextViewAdditions.m
//  QiYReader
//
//  Created by 奇阅科技 on 14/12/8.
//  Copyright (c) 2014年 奇阅科技. All rights reserved.
//

#import "UITextViewAdditions.h"

@implementation UITextViewAdditions
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    
    [[self nextResponder] touchesBegan:touches withEvent:event];
    
    [super touchesBegan:touches withEvent:event];
    
}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    
    [[self nextResponder] touchesMoved:touches withEvent:event];
    
    [super touchesMoved:touches withEvent:event];
    
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    
    UITouch *touchPint = [touches anyObject];
    
    // 取这个点点击的位置是在左边还是右边，并向delegate发出事件
    
    CGPoint clickedPoint = [touchPint locationInView:self];
    NSLog(@"%f---%f",clickedPoint.x,self.frame.size.width);
    if (clickedPoint.x > (self.frame.size.width/3)*2) {
        
        NSLog(@"Right");
        
        if ([self.readDelegate respondsToSelector:@selector(clickRightDetect)]) {
            
            [self.readDelegate clickRightDetect];
            
        }
        
    }else if (clickedPoint.x < self.frame.size.width/3) {
        
        if ([self.readDelegate respondsToSelector:@selector(clickRightDetect)]) {
            
            [self.readDelegate clickLeftDetect];
            
        }
        
        NSLog(@"Left");
        
    }else{
        if ([self.readDelegate respondsToSelector:@selector(clickMiddleDetect)]) {
            
            [self.readDelegate clickMiddleDetect];
            
        }
        
        NSLog(@"Middle");
    }
    
    
    
    [[self nextResponder] touchesEnded:touches withEvent:event];
    
    [super touchesEnded:touches withEvent:event];
    
}

@end
